package com.zzyang.mybatis.jdbc.loadbalance;

import java.util.List;
import java.util.Random;

/**
 * 随机选取
 *
 * @author zhuoziyang
 * @date 2021/4/8 21:34
 */
public class RandomLoadBalance extends AbstractLoadBalance {

    private Random random = new Random();

    @Override
    public String doSelect(List<String> dataSourceIds) {
        int size = dataSourceIds.size();
        int randomIndex = random.nextInt(size);
        return dataSourceIds.get(randomIndex);
    }

}
